﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Library.DAL;

namespace Library.BLL
{
    public class PessoaController: BaseController
    {
        const string tableName = "PESSOAL";
        public PessoaController():base(tableName) 
        {
        }

        public DataTable getListaDadosUsuario()
        {
            string query = " SELECT COD_PESSOA, NOME_PESSOA FROM PESSOAL ";
            return this.executeQuery(query);
        }

        public DataTable getDadosUsuario(int codigoUsuario)
        {
            string query = " SELECT * FROM PESSOAL WHERE COD_PESSOA = " + codigoUsuario;
            return this.executeQuery(query);
        }

        public DataTable createDataTable()
        {
            DataTable dt = new DataTable(tableName);
            dt.Columns.Add(new DataColumn("COD_PESSOA",typeof(int)));
            dt.Columns.Add(new DataColumn("NOME_PESSOA",typeof(string)));
            dt.Columns.Add(new DataColumn("CARGO_FUNCAO",typeof(string)));
            dt.Columns.Add(new DataColumn("RG",typeof(string)));
            dt.Columns.Add(new DataColumn("CATEGORIA",typeof(string)));
            dt.Columns.Add(new DataColumn("PAGTO_MENSAL",typeof(double)));
            dt.Columns.Add(new DataColumn("COD_BANCO",typeof(Int32)));
            dt.Columns.Add(new DataColumn("AGENCIA", typeof(string)));
            dt.Columns.Add(new DataColumn("CONTA_CORRENTE", typeof(string)));
            dt.Columns.Add(new DataColumn("NIVEL",typeof(string)));
            dt.Columns.Add(new DataColumn("UO",typeof(string)));
            dt.Columns.Add(new DataColumn("UGE",typeof(string)));
            dt.Columns.Add(new DataColumn("SEDE",typeof(string)));
            dt.Columns.Add(new DataColumn("DT_CADASTRO",typeof(DateTime)));
            
            return dt;
        }

        public Int32 getNextCodigoUsuario()
        {
            string query = " SELECT MAX(COD_PESSOA) + 1 FROM PESSOAL ";
            return Convert.ToInt32((this.executeQuery(query)).Rows[0][0]);
        }
    }
}
